﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SDL;

namespace BusinessLogic
{
    public partial class UserInfo
    {
        public static int OnlineTimeOut = 20;

        public List<UserInfo> getFriends()
        {
            var n = new UserInfo();
            n["id"] = this.Id;
            n.Run("user.getFriends");
            return new List<UserInfo>(n.getList<UserInfo>());
        }

        public void addFriend(Guid fid)
        {
            var n = new UserInfo();
            n["id"] = this.Id;
            n["fid"] = fid;
            n.Run("user.addFriend");            
        }

        public bool isOnline()
        { 
            TimeSpan ts = DateTime.Now - (DateTime)LastActivity;
            return (ts.TotalMinutes <= OnlineTimeOut);
        }

        public void save()
        {
            this.Run("user.update", true);
        }
    }
}
